package com.xquant.transaction_management_system.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xquant.transaction_management_system.mapper.AccountMapper;
import com.xquant.transaction_management_system.model.PO.Account;
import com.xquant.transaction_management_system.model.PO.FinancialInstruments;
import com.xquant.transaction_management_system.service.AccountService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {
    @Override
    public boolean login(Account account) {
        QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("transaction_account",account.getTransactionAccount());
        Account selectOne = baseMapper.selectOne(queryWrapper);
        if (selectOne==null){
            baseMapper.insert(account);
            return true;
        }
        if (selectOne.getPassword().equals(account.getPassword())){
            return true;
        }
        return false;
    }

    @Override
    public IPage<Account> getAccontByPage(Page<Account> pageParam) {
        QueryWrapper<Account> accountQueryWrapper = new QueryWrapper<>();
        IPage<Account> page = baseMapper.selectPage(pageParam, accountQueryWrapper);
        return page;
    }

    @Override
    public List<Account> getAll() {
        QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
        List<Account> accounts = baseMapper.selectList(queryWrapper);
        return accounts;
    }
}
